import java.util.Arrays;
import java.util.Locale;

class Student{
    String name;
    int age;

    public Student(String name, int age){
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}


public class Test {
    public static void main(String[] args) {
        //trim() 去除两边空格，保留中间空格
        String s = "  asd ssd sad ";
        String ret = s.trim();
        System.out.println(ret);
    }


    public static void main16(String[] args) {
        //字符串的截取: 从指定位置到结尾
        String s1 = "abcdefg";
        String ret = s1.substring(0);
        System.out.println(ret);
        String ret1 = s1.substring(3);
        System.out.println(ret1);

        //截取部分，左闭右开
        String ret2 = s1.substring(2,4);
        System.out.println(ret2);
    }


    public static void main15(String[] args) {
     //部分需要转义 “|”“\\”“.”“+”“*”
     String s1 = "178.1.1.23.43";
     String[] ret = s1.split("\\.");
     System.out.println(Arrays.toString(ret));

     //存在两种字符以上用

     String s2 = "178 = 1=21.123.512.36213=2313";
     String[] ret1 = s2.split("=");
     for(String x : ret1){
         String[] ret2 = x.split("\\.");
         for(String ss : ret2){
             System.out.println(ss);
         }
     }
    }


    public static void main14(String[] args) {
        //字符串的拆分
        String s1 = "abc = def = ghi";
        String[] ret = s1.split("=");
        System.out.println(Arrays.toString(ret));

        //拆分为几组
        String[] ret1 = s1.split("=",2);
        System.out.println(Arrays.toString(ret1));

        String[] ret2 = s1.split("=", 3);
        System.out.println(Arrays.toString(ret2));
    }


    public static void main13(String[] args) {
        //字符串替换
        String s1 = "ababefef";
        String ret = s1.replaceAll("ab","cd");
        System.out.println(ret);

        //替换第一个
        String ret1 = s1.replaceFirst("ab","cd");
        System.out.println(ret1);
    }

    public static void main12(String[] args) {
        //字符串转化成数组
        String s1 = "abcdef";
        char[] ch = s1.toCharArray();
        System.out.println(Arrays.toString(ch));

        //格式化
        String s =  String.format("%d-%d-%d",2025,10,11);
        System.out.println(s);
    }


    public static void main11(String[] args) {
        String s = "ABCdef";

        //转化为大写
        String ret1 = s.toUpperCase();
        //转化为小写
        String ret2 = s.toLowerCase();
        System.out.println(ret1);
        System.out.println(ret2);
    }


    public static void main10(String[] args) {
        //转化
        String s1 = String.valueOf(70);
        String s2 = String.valueOf('b');
        String s3 = String.valueOf(12.67);

        //把引用转化为String
        Student student = new Student("bit", 10);
        String s4 = String.valueOf(student);

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);

        int a = Integer.parseInt("1234");
        System.out.println(a + 1);
    }


    public static void main9(String[] args) {
        String s = "abcabceded";
        //从后往前找
        int index = s.lastIndexOf("ab");
        System.out.println(index);

        //从指定下标开始往前找
        int index2 = s.lastIndexOf("ab", 2);
        System.out.println(index2);

    }


    public static void main8(String[] args) {
        String s = "abcabceded";
        int index = s.indexOf("abc");
        System.out.println(index);

        int index2 = s.indexOf("abc", 3);
        System.out.println(index2);
    }


    public static void main7(String[] args) {
        String s1 = "ababcdcd";
        char ch = s1.charAt(1);
        System.out.println(ch);

        //返回字符第一次出现的位置
        int index = s1.indexOf('c');
        System.out.println(index);

        //在字符中，从下标5开始找，字符c的位置
        int index2 = s1.indexOf('c', 5);
        System.out.println(index2);
    }

    public static void main6(String[] args) {
        String s1 = "Abcdef";
        String s2 = "abcdef";

        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareToIgnoreCase(s2));
    }


    //对于引用类型变量，==比较两个引用是否为同一变量
    public static void main5(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("bit");
        String s3 = s1;
        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
    }


    public static void fun(String str){
        System.out.println(str);
    }

    public static void main4(String[] args) {
        String str = "abcdef";
        fun(str);
    }


    public static void main3(String[] args) {
        String s1 = "abdcd";

        String s2 = "";

        System.out.println(s1.length());

        System.out.println(s2.isEmpty());  //isEmpty() 如果是0 返回true ，否则返回false
    }


    public static void main2(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("bit");
        String s3 = s1;

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s1.equals(s3));
    }


    //字符串构造
    public static void main1(String[] args) {
        //第一种
        String str1 = "abdcdfg";
        System.out.println(str1);

        //第二种
        String str2 = new String("heloo");
        System.out.println(str2);

        //第三种
        char[] value = {'n','n','m'};
        String str3 = new String(value);
        System.out.println(str3);
    }
}
